<template>
	<view class="content">
			<view class="section-0">
				<view class="section-body">
					<view class="item" v-for="item in board" :key="item.name">
						<view class="shape" v-if="item.right"></view>
						<view class="shape2" v-if="item.bottom"></view>
						<view class="top">{{item.name}}</view>
						<view class="bottom">{{analysis[item.type]}}</view>
					</view>
				</view>
			</view>
			<view class="section-1">
			<view class="form">
				<view class="form-item">
					<view class="label">项目名称</view>
					<view class="shape"></view>
					<view class="input">
						<u--input
							placeholderClass="input-placeholder"
							class="input-body"
						    placeholder="项目名称"
						    v-model="form.projectName"
						  ></u--input>
					</view>
				</view>
				<view class="actions">
					<view class="action" @click="handleResetForm()">
						<text>重</text>
						<text>置</text>
					</view>
					<view class="action search" @click="handleSearch()">
						<text>查</text>
						<text>询</text>
					</view>
				</view>
			</view>
			<view class="list" v-if="Object.keys(list).length > 0">
				<view :class="`item ${expandList.indexOf(key) !== -1 ? 'item__expand' : ''}`" v-for="(value, key, index) in list" :key="key">
					<view class="parent">
						<view class="action" @click="expandChange(key)">
							<view class="iconfont icon-xiala"></view>
						</view>
						<view class="name">
							{{index + 1}}.{{key}}
						</view>
						<view class="count">{{value.length}}<text>个</text></view>
					</view>
					<view class="child" v-if="expandList.indexOf(key) !== -1">
						<view class="child-item" @click="go(item2)" v-for="(item2, idx) in value" :key="item2.work_type + idx">
							<view class="top">
								<view class="name">
									{{idx + 1}}.{{item2.project_name}}
								</view>
								<view class="action">
									<view class="iconfont icon-xiangyou1"></view>
								</view>
							</view>
							<view class="info">
								<view>{{item2.work_type}}</view>
								<view>等级{{item2.risk_level}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="custom-empty">
				<text class="iconfont icon-zanwushuju"></text>
				<view class="empty-title">暂无数据</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { projectRiskAnalysisApi, projectRiskListApi } from '@/api/statistics.js';
	import { mapGetters, mapActions} from 'vuex';
	export default {
		data() {
			return {
				form: {
					project_name: ''
				},
				name: '',
				board: [
					{ name: '风险总数', count: 0, right: true, bottom: true, type: 'risk_num' },
					{ name: '二级风险', count: 0, right: true,  bottom: true, type: 'risk_num_2' },
					{ name: '三级风险', count: 0, bottom: true, type: 'risk_num_3' },
					{ name: '作业票', count: 0, right: true, type: 'work_count' },
					{ name: '二级到岗率', count: 0, right: true, type: 'risk_ratio_2' },
					{ name: '三级到岗率', count: 0, type: 'risk_ratio_3' },
				],
				list: {},
				expandList: [],
				analysis: {}
			};
		},
		methods: {
			expandChange(id) {
				const idx = this.expandList.indexOf(id);
				if (idx !== -1) {
					this.expandList.splice(idx, 1);
				} else {
					this.expandList.push(id);
				}
			},
			go(params) {
				uni.navigateTo({
					url: '/pages/statistics/today/risk/info/index?params=' + JSON.stringify(params)
				})
			},
			async projectAnalysis() {
				uni.showLoading({title: '加载中...'});
				const { data } = await projectRiskAnalysisApi();
				uni.hideLoading();
				if (data.code === 1) {
					this.analysis = data.data;
				}
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			async fetchData() {
				uni.showLoading({title: '加载中...'});
				const { data } = await projectRiskListApi({...this.form});
				uni.hideLoading();
				if (data.code === 1) {
					let map = {}
					data.data.forEach(item => {
						if(!map[item.project_name]) {
							map[item.project_name] = []
						}
						map[item.project_name].push(item);
					})
					this.list = map;
				}
			},
			
			handleResetForm(){
				for (let key in this.form) {
					this.form[key] = '';
				}
				this.fetchData();
			},
			handleSearch(){
				this.fetchData();
			},
		},
		onReady() {
			this.projectAnalysis();
			this.fetchData();
		}
	}
</script>

<style lang="scss" scoped>
	.custom-empty{
		position: static;
	}
	.content{
		background-color: #fff;
	}
	.section-1{
		position: relative;
		top: -50rpx;
		z-index: 10;
		background-color: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		.list{
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;
			.item{
				width: 100%;
				border-bottom: solid 2rpx #f2f2f0;
				.parent{
					width: 100%;
					height: 82rpx;
					.name{
						width: 520rpx;
						height: 82rpx;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 82rpx;
						letter-spacing: 2rpx;
						color: #3b3c40;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
						float: left;
					}
					.count{
						float: right;
						min-width: 46rpx;
						height: 46rpx;
						margin-top: 18rpx;
						border-radius: 28rpx;
						line-height: 46rpx;
						text-align: center;
						font-size: 26rpx;
						font-weight: bold;
						color: #395cf5;
						background: #ffde00;
						margin-right: 40rpx;
						text{
							font-size: 16rpx;
						}
					}
					.action{
						float: left;
						width: 32rpx;
						margin-right: 18rpx;
						height: 100%;
						line-height: 82rpx;
						text-align: center;
						color: #3b3c40;
						.iconfont{
							font-size: 32rpx;
							transition: 0.2s ease;
						}

					}
				}
				.child{
					width: 750rpx;
					margin-left: - 40rpx;
					background: #f2f2fa;
					.child-item{
						width: 620rpx;
						margin-left: 90rpx;
						border-bottom: 2rpx solid #e3e8f5;
						position: relative;
						&:last-child{
							border-bottom: none;
						}
						.top{
							width: 100%;
							overflow: hidden;
							height: 70rpx;
							.name{
								float: left;
								width: 620rpx;
								height: 70rpx;
								line-height: 70rpx;
								color: #3b3c40;
								font-size: 26rpx;
								text-overflow: ellipsis;
								overflow: hidden;
								white-space: nowrap;
							}
							.action{
								position: absolute;
								width: 40rpx;
								height: 70rpx;
								line-height: 70rpx;
								top: 20rpx;
								right: 0;
								text-align: right;
								color: #7f98ae;
								.iconfont{
									font-size: 26rpx;
								}
							}
						}
						
						.info{
							height: 40rpx;
							overflow: hidden;
							view{
								height: 24rpx;
								line-height: 24rpx;
								float: left;
								margin-right: 20rpx;
								font-size: 18rpx;
								color: #7f98ae;
							}
						}
					}
				}
			}
			.item__expand{
				.parent{
					.action{
						.iconfont{
							transform: rotate(-180deg);
						}
					}
				}
				.child{
					box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(0, 0, 0, 0.05) inset;
				}
			}
		}
		.actions{
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			.action{
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				line-height: 48rpx;
				color: #ffffff;
				text{
					&:first-child{
						margin-right: 20rpx;
					}
				}
			}
			.search{
				background-color: #1534ce;
			}
		}
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape{
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input{
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.input-body{
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0!important;
						border: none;
						padding-left: 30rpx!important;
						padding-right: 30rpx!important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
					}
					.input-placeholder{
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.5);
					}
				}	
			}
		}
	}
	.section-0{
		width: 100%;
		background-color: #2e5efe;
		.section-body{
			width: 100%;
			height: 340rpx;
			padding-left: 40rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			padding-top: 20rpx;
			background-color: #1534ce;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			overflow: hidden;
			box-sizing: border-box;
			.item{
				width: 33.33%;
				float: left;
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				height: 100rpx;
				position: relative;
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				.shape{
					width: 4rpx;
					height: 84rpx;
					background-image: linear-gradient(rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%,);
					position: absolute;
					right: 0;
					top: 28rpx;
				}
				.shape2{
					height: 4rpx;
					width: 172rpx;
					background-image: linear-gradient(90deg, rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%,);
					position: absolute;					
					left: 0;
					right: 0;
					margin: 0 auto;
					bottom: -2rpx;
				}
				.top{
					width: 100%;
					text-align: center;
					font-size: 16rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #95c4fa;
				}
				.bottom{
					width: 100%;
					text-align: center;
					font-size: 58rpx;
					font-weight: bold;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #ffde00;
				}
			}
		}
	}
</style>
